package com.gszyxy.mallfour.plateform.handler;


import com.gszyxy.mallfour.plateform.pojo.PlateformMerchant;
import com.gszyxy.mallfour.plateform.service.PlateformService;
import com.gszyxy.mallfour.utils.R;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("plateform")
public class PlateformHandler {
    @Resource
    private PlateformService plateformService;


    @GetMapping("list")
    public R list() {
        return plateformService.list().size() > 0 ? R.ok(plateformService.list()) : R.fail("暂时无商家入驻");


    }


    @PostMapping("access")
    public R access(@RequestParam("mid") Integer mid, HttpServletRequest request) {

        String loginUser = (String) request.getSession().getAttribute("mname");

        if (!loginUser.equals("admin")) {
            return R.fail("您不是管理员,没有审核权限");
        }

        return plateformService.updateMerchant(mid) == 1 ? R.ok("审核成功") : R.fail("审核失败");
    }

    @PostMapping("unstatus")
    public R unstatus(@RequestParam("mid") Integer mid, HttpServletRequest request) {

        String loginUser = (String) request.getSession().getAttribute("mname");

        if (!loginUser.equals("admin")) {
            return R.fail("您不是管理员,没有审核权限");
        }

        return plateformService.updateUnStatusByMid(mid) == 1 ? R.ok("审核成功") : R.fail("审核失败");
    }



    @GetMapping("queryByCondtion")
    public R condition(@RequestParam("mrealName") String mrealName) { // @PathVariable 作用：获取地址栏上的请求参数
//        System.out.println("=========>" + mrealName);
        return plateformService.findByCondition(mrealName) == null ? R.fail("没有数据") : R.ok(plateformService.findByCondition(mrealName));
    }




}
